/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.amuthu.expression.function.indicator;

import org.amuthu.DataStore;
import org.amuthu.expression.Expression;
import org.amuthu.parser.ExpressionVisitor;

/**
 *
 * @author prabhus
 */
public abstract class MacdFunctionBase extends BaseIndicatorFunction
{
   private int fastPeriod;
   private int slowPeriod;

   public int getFastPeriod()
   {
      return fastPeriod;
   }

   public void setFastPeriod(int fastPeriod)
   {
      this.fastPeriod = fastPeriod;
   }

   public int getSlowPeriod()
   {
      return slowPeriod;
   }

   public void setSlowPeriod(int slowPeriod)
   {
      this.slowPeriod = slowPeriod;
   }

   @Override
   public boolean doUpdateParameters(DataStore dataStore, Expression[] arguments, ExpressionVisitor visitor)
   {
      if (arguments.length < 3)
      {
         return false;
      }

      fastPeriod = (int) visitor.evaluate(arguments[0]);

      if (fastPeriod < 0)
      {
         return false;
      }

      slowPeriod = (int) visitor.evaluate(arguments[1]);

      if (slowPeriod < 0)
      {
         return false;
      }

      int period = (int) visitor.evaluate(arguments[2]);

      if (period < 0)
      {
         return false;
      }

      int startOffset = (arguments.length > 3) ? (int) visitor.evaluate(arguments[3]) : 0;

      setPeriod(period);
      setOffset(startOffset);

      return true;
   }
}
